// my-behavior.js
let systemInfo = {}
module.exports = Behavior({
  data: {
    msg: 'hello',
    mainHeight: 0,
    statusBarHeight: 44
  },
  created(){
    wx.getSystemInfo({
      success: res => systemInfo = res,
      fail: err => console.log(err)
    })
  },
  methods: {
    /**
     * 获取选择器的高度，两个参数：1、选择器数组 2、是否减去全屏手机底部导航指引的高度（仅IOS时需要设置）
     */
    getRect(){
      let seletor = [...arguments]
      var that = this;
  　　//我这里需要获取多个元素的高度，所以用的是selectAll
      wx.createSelectorQuery().selectAll(seletor[0].join()).boundingClientRect().exec(function(res){
        let allRectH = []
        const { screenHeight, screenWidth, windowHeight, safeArea, statusBarHeight } = systemInfo
        console.log(screenHeight);
        for (let i = 0; i < seletor[0].length; i++) {
          allRectH.push(res[0][i].height)
        }
        const totalH = allRectH.reduce((prev,curr) => {
          return prev + (curr)
        }, 0)
        const safeAreaBottom = screenHeight - safeArea.bottom
        let mainHeight = screenHeight - totalH - safeAreaBottom - statusBarHeight - 44 //自定义头部导航栏时使用屏幕高度
        // let mainHeight = windowHeight - totalH - safeAreaBottom -statusBarHeight - 44 //未使用自定义头部导航栏时使用窗口高度
        that.setData({
          mainHeight,
          statusBarHeight
        })
      })
    },
  }
})